<html><head><meta charset="gb2312"/><title>Palette.pb</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><font color="#3A3966">;   PureBasic - Palette example file
</font><font color="#3A3966">;
</font><font color="#3A3966">;    (c) 2004 - Fantaisie Software
</font><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><b><font color="#3A3966">CompilerIf</font></b> <font color="#3A3966">Subsystem</font>("directx7") = 0
  <b><font color="#3A3966">CompilerError</font></b> "This example only works with the DirectX7 subsystems"
<b><font color="#3A3966">CompilerEndIf</font></b>

<b><font color="#3A3966">If</font></b> <font color="#3A3966">InitSprite</font>() = 0 <b><font color="#3A3966">Or</font></b> <font color="#3A3966">InitKeyboard</font>() = 0 <b><font color="#3A3966">Or</font></b> <font color="#3A3966">InitPalette</font>() = 0
<font color="#3A3966">  MessageRequester</font>("Error", "Can't open DirectX 7 or later", 0)
  <b><font color="#3A3966">End</font></b>
<b><font color="#3A3966">EndIf</font></b>

<b><font color="#3A3966">If</font></b> <font color="#3A3966">OpenScreen</font>(640, 480, 8, "PureBasic - Palette Example")
<font color="#3A3966">  LoadSprite</font>(0, "Data\AlphaChannel.bmp", 0)
  
  <font color="#3A3966">; Build 256 precalculated palette to do a nice cycling effect !
</font>  <font color="#3A3966">;
</font>  <b><font color="#3A3966">For</font></b> Palette = 0 <b><font color="#3A3966">To</font></b> 255
<font color="#3A3966">    CreatePalette</font>(Palette)
      <b><font color="#3A3966">For</font></b> Index = 1 <b><font color="#3A3966">To</font></b> 255  <font color="#3A3966">; Let the first color always Black
</font>        Color = Index+Palette
        <b><font color="#3A3966">If</font></b> Color &#062; 255
          Color - 256
        <b><font color="#3A3966">EndIf</font></b>
        
<font color="#3A3966">        SetPaletteColor</font>(Palette, Index, Color &#060;&#060; 8)
      <b><font color="#3A3966">Next</font></b>
  <b><font color="#3A3966">Next</font></b>
  
  Palette = 0
  <b><font color="#3A3966">Repeat</font></b>
<font color="#3A3966">    FlipBuffers</font>()                                 <font color="#3A3966">; Flip for DoubleBuffering
</font><font color="#3A3966">    ClearScreen</font>(<font color="#3A3966">RGB</font>(0, 0, 0))
    
<font color="#3A3966">    DisplayPalette</font>(Palette)
<font color="#3A3966">    DisplaySprite</font>(0, 100, 100)
    
    Palette+1
    <b><font color="#3A3966">If</font></b> Palette &#062; 255 : Palette = 0 : <b><font color="#3A3966">EndIf</font></b>
      
<font color="#3A3966">    ExamineKeyboard</font>()
  <b><font color="#3A3966">Until</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#FF0000">#PB_Key_Escape</font>)
<b><font color="#3A3966">EndIf</font></b>

<b><font color="#3A3966">End</font></b>  
  </font></pre>
</body></html>
